# Maintainer: Feng Shu <tumashu@163.com>

_realname=opencc
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.6
pkgrel=1
pkgdesc="Library for Open Chinese Convert (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/BYVoid/OpenCC"
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-python")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/BYVoid/OpenCC/archive/ver.${pkgver}.tar.gz")
sha256sums=('169bff4071ffe814dc16df7d180ff6610db418f4816e9c0ce02cf874bdf058df')

prepare() {
   mv "${srcdir}/OpenCC-ver.${pkgver}" "${_realname}-${pkgver}"
   cd "${_realname}-${pkgver}"
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe -Wclass-memaccess\
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    -DENABLE_GTEST=OFF \
    -DBUILD_SHARED_LIBS=OFF \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python.exe \
    "../${_realname}-${pkgver}"

  cmake --build .
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  ctest
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" cmake --install .
}
